﻿using System;

namespace cludg.Domain.Content.Stories
{
	public class Offer : IContent
	{
		public virtual string Id { get; set; }
		public virtual Users.User Author { get; set; }
		public virtual DateTime CreationTime { get; set; }
		public virtual StorySubject Subject { get; set; }
		public virtual string Comment { get; set; }
		public virtual string Title { get; set; }
		public virtual string AnonymouseAuthorName { get; set; }

		public virtual OfferState State { get; protected set; }
		public virtual Users.User OfferedBy { get; protected set; }
		public virtual DateTime? OfferingTime { get; protected set; }
		public virtual string ApprovedStoryId { get; protected set; }

		public enum OfferState
		{
			Offered,
			Approved,
			Declined
		}

		public Offer()
		{
			State = OfferState.Offered;
			OfferedBy = null;
			ApprovedStoryId = null;
			OfferingTime = null;
		}

		public virtual void Approve(Users.User approvedBy, Story approvedStory, DateTime approvingTime)
		{
			State = OfferState.Approved;
			OfferedBy = approvedBy;
			ApprovedStoryId = approvedStory.Id;
			OfferingTime = approvingTime;
		}

		public virtual void Decline(Users.User declinedBy, DateTime decliningTime)
		{
			State = OfferState.Declined;
			OfferedBy = declinedBy;
			OfferingTime = decliningTime;
			ApprovedStoryId = null;
		}
	}
}
